
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>列表</title>
    {include file="include/top"}
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            {include file="include/selectsearch" title="等级" classname='level' optionHtml='<?php echo isset($levels)?$levels:"";?>' }
            {include file="include/input" class2='layui-inline' type='text' title="昵称" name='nickname' value=''}
            {include file="include/input" class2='layui-inline' type='text' title="姓名" name='username' value=''}
            {include file="include/input" class2='layui-inline' type='text' title="手机号" name='mobile' value=''}
            {include file="include/input" class2='layui-inline' type='text' title="证件号" name='carID' value=''}
            <div class="layui-inline">
                <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                    <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                </button>
            </div>
        </div>
<!--        <div class="layui-card-header layuiadmin-card-header-auto">-->
<!--            <button type="button" class="layui-btn layui-btn-warm" id="test-upload-type3" data-imgid="adduser"><i class="layui-icon"></i>批量停止</button>-->
<!--            <button type="button" class="layui-btn layui-btn-warm" id="test-upload-type4" data-imgid="adduser"><i class="layui-icon"></i>批量正常</button>-->
<!--        </div>-->
        <table class="layui-table" lay-data="{height:0, url:'levelLogList', page:true, id:'idTest',toolbar: '#toolbarDemo' ,cellMinWidth: 80}" lay-filter="demo">
            <thead>
            <tr>
                <th lay-data="{type:'checkbox'}"></th>
                <th lay-data="{field:'id',  sort: true, width:80}">ID</th>
                <th lay-data="{field:'uid'}">用户ID</th>
                <th lay-data="{field:'nickname'}">昵称</th>
                <th lay-data="{field:'username'}">姓名</th>
                <th lay-data="{field:'admin'}">管理员ID</th>
                <th lay-data="{field:'adminName'}">管理员</th>
                <th lay-data="{field:'levelStr'}">设置等级</th>
                <th lay-data="{field:'addTime'}">时间</th>

            </tr>
            </thead>
        </table>
        <script type="text/html" id="barDemo">
            <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="more">操作<i
                    class="layui-icon layui-icon-down"></i></a>
        </script>
        <script type="text/html" id="toolbarDemo"></script>
    </div>
</div>
<input type='file' id='upimg' name='file' style="display: none;">
{include file="include/js"}
<script>
    var pathid=0;
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'contlist', 'table','dropdown','upload'], function(){
        var table = layui.table;
        var $ = layui.$;
        var form = layui.form;
        var dropdown = layui.dropdown
        var pathid=0;
        var id=0;
        var selectIDS=[];
        var upload = layui.upload;
        var imgType=0;
        var imgSrc='';
        var field;
        //监听搜索
        form.on('submit(LAY-app-contlist-search)', function(data){
            field = data.field;
            //执行重载
            table.reload('idTest', {
                where: field,page:{curr:1}
            });
        });
        $('.layui-btn.layuiadmin-btn-tags').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听工具条
        table.on('tool(demo)', function(obj){
            var that = this
            var data = obj.data;
            if (obj.event === 'more') {
                //更多下拉菜单
                var thatData = data
                dropdown.render({
                    elem: that
                    , show: true //外部事件触发即显示
                    , data: [{
                        title: '编辑'
                        , id: 'edituser'
                    },{
                        title: '充值'
                        , id: 'recharge'
                    },{
                        title: '等级'
                        , id: 'level'
                    },{
                        title: '禁用'
                        , id: 'setDisable'
                    },
                    ]
                    , click: function (data, othis) {
                        //根据 id 做出不同操作
                        if (data.id === 'del') {
                            layer.confirm('是否确定删除?', function (index) {

                                id = thatData.orderProductID
                                delUser(obj)
                                layer.closeAll();
                            });
                        }else if(data.id == 'edituser'){
                            id = thatData.id
                            userAdd();
                        }else if(data.id == 'level'){
                            id = thatData.id
                            layer.confirm("请选择会员等级",{btn:['取消','用户','店家','商家','游客'],area:['500px','160px'],btn1:function (){
                                    layer.closeAll()
                                },btn2:function (){
                                    setUserLevel(236)
                                },btn3:function (){
                                    setUserLevel(247)
                                },btn4:function (){
                                    setUserLevel(248)
                                },btn5:function (){
                                    setUserLevel(0)
                                }
                            })
                        }else if(data.id == 'recharge'){
                            id = thatData.id
                            rechargeAdmin2();
                        }
                    }
                    , align: 'right' //右对齐弹出（v2.6.8 新增）
                    , style: 'box-shadow: 1px 1px 10px rgb(0 0 0 / 12%);' //设置额外样式
                });
            }
        });
        function setUserLevel($cint=0){
            layer.confirm("是否确定操作？",function (){
                $.post("setUserLevel?userID="+id,{level:$cint},function (re) {
                    layer.msg(re.msg);
                },'json');
            })
        }
        function rechargeAdmin2(){
            layer.open({
                type: 2
                ,title: '手动充值'
                ,content: 'rechargeAdmin2?userID='+id+"&id=0"
                ,btn: ['确定', '取消']
                ,area: ['40%', '60%']
                ,yes: function(index, layero){
                    layer.confirm('是否确定操作?', {icon: 3, title:'提示'}, function(index){
                        //do something
                        var data={}
                        var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags");
                        data.amount = othis.find('input[name="amount"]').val()
                        data.img = othis.find('input[name="img"]').val()
                        data.pays = othis.find('select[name="pays"]').val()
                        $.post("rechargeAdmin2Save?userID="+id,data,function (re) {
                            layer.msg(re.msg);
                        },'json');
                        layer.closeAll();
                    });
                }
            });
        }
        upload.render({
            elem: '#upimg'
            ,url: '/includes/upload' //此处配置你自己的上传接口即可
            ,done: function(res){
                layer.msg(res.msg)
                if(res.code==0){
                    imgSrc = res.data.url
                    if(imgType>0){
                        $("#myimg"+imgType).attr("src",imgSrc)
                    }else{
                        $("#myimg").attr("src",imgSrc)
                    }

                }
            }
        });
        $("#test-upload-type1").click(function () {
            id=0
            userAdd()
        });
        $("#test-upload-type2").click(function () {
            layer.confirm("是否批量购买保险？",function (){
                $.post("isSureIDS?id="+id,{ids:JSON.stringify(selectIDS)},function (re) {
                    layer.msg(re.msg,function (){
                        if(re.code == 0 ){
                            table.reload('idTest', {
                                where: field
                            });
                        }
                    });
                },'json');
                layer.closeAll();
            })
        });
        $("#test-upload-type3").click(function () {
            layer.confirm("是否批量状态禁用账号？",function (){
                $.post("setStatus?id="+id,{ids:JSON.stringify(selectIDS),status:-1},function (re) {
                    layer.msg(re.msg,function (){
                        if(re.code == 0 ){
                            table.reload('idTest', {
                                where: field
                            });
                        }
                    });
                },'json');
                layer.closeAll();
            })
        });
        $("#test-upload-type4").click(function () {
            layer.confirm("是否批量状态正常？",function (){
                $.post("setStatus?id="+id,{ids:JSON.stringify(selectIDS),status:0},function (re) {
                    layer.msg(re.msg,function (){
                        if(re.code == 0 ){
                            table.reload('idTest', {
                                where: field
                            });
                        }
                    });
                },'json');
                layer.closeAll();
            })
        });
        $(document).on("click","#upimg2",function (){
            imgType = $(this).data("id")
            $("#upimg").trigger("click")
        })
        table.on('checkbox(demo)', function(obj){
            var checkStatus = table.checkStatus('idTest');
            if(checkStatus.isAll==true){
            }
            selectIDS=[];
            var data = checkStatus.data;
            for (var i in data){
                selectIDS.push(data[i].id)
            }

        });
        function userAdd(){
            layer.open({
                type: 2
                ,title: '添加用户或修改用户'
                ,content: 'userAdd?id='+id
                ,btn: ['确定', '取消']
                ,area: ['100%', '80%']
                ,yes: function(index, layero){
                    layer.confirm('是否确定操作?', {icon: 3, title:'提示'}, function(index){
                        //do something
                        var data={}
                        var othis = layero.find('iframe').contents().find("#layuiadmin-app-form-tags");
                        data.nickname = othis.find('input[name="nickname"]').val()
                        data.levelTime = othis.find('input[name="levelTime"]').val()
                        // data.agent = othis.find('input[name="agent"]').val()
                        // data.agentCite = othis.find('input[name="agentCite"]').val()
                        data.agentTime = othis.find('input[name="agentTime"]').val()
                        $.post("userSave?id="+id,data,function (re) {
                            layer.msg(re.msg);
                            setTimeout(function () {
                                location.reload();
                            },2000);
                        },'json');
                        layer.closeAll();
                    });
                }
            });
        }
    });
</script>

</body>
</html>
